package leetcode每日一题;

import java.util.Arrays;

@SuppressWarnings("all")
public class 吃早餐 {
    public static void main(String[] args) {

    }

    /**
     * 排序 + 双指针
     * @param staple
     * @param drinks
     * @param x
     * @return
     */
    public static int breakfastNumber(int[] staple, int[] drinks, int x) {
        Arrays.sort(staple); Arrays.sort(drinks);
        int lens = staple.length; int lend = drinks.length;
        int ans = 0;
        int i = 0; int j = lend - 1;
        while (i < lens && j >= 0) {
            if (staple[i]+drinks[j] <= x) {
                ans = (ans + j + 1) % 1000000007;
                i++;
            } else {
                j--;
            }
        }
        return ans % 1000000007;
    }
}
